<!--个人主页-->
<script setup lang="js">
import PersonPage from "@/renderer/main-window/components/PersonPage.vue";
import {summonerInfoStore} from "@/renderer/main-window/stores/storeSummonerInfo.js";
import {ref} from "vue";
import LcuProfile from "@share/components/lcu/LcuProfile.vue";


const otherSummonerList = ref([]);

const currentShowTab = ref('主页');
const handleDeleteTag = (puuid) => {
  const newTabs = otherSummonerList.value.filter(item => {
    return item.value !== puuid;
  })
  otherSummonerList.value = [...newTabs];
  currentShowTab.value = '主页';
}

const handleJumpToOtherSummoner = ({puuid}) => {
  const filterList = otherSummonerList.value.filter(item => {
    return item.value === puuid;
  });
  if (filterList.length > 0) {
    currentShowTab.value = filterList[0].label;
    return;
  }

  window.api.summoner.getSummonerInfoByPuuid(puuid)
      .then(res => {
        return Promise.resolve(res.data)
      })
      .then(summonerInfoTemp => {
        window.api.summoner.getSummonerProfileByPuuid(puuid).then(res => {
          const label = `${summonerInfoTemp.gameName}#${summonerInfoTemp.tagLine}`;
          otherSummonerList.value.push({
            'label': label,
            'value': summonerInfoTemp?.puuid,
            "summonerInfo": summonerInfoTemp,
            "summonerProfileInfo": res.data,
          })
          currentShowTab.value = summonerInfoTemp.puuid;
        })
      })

}
</script>

<template>
  <el-tabs
      v-model="currentShowTab"
      type="card"
      @tab-remove="handleDeleteTag"
  >
    <el-tab-pane
        :closable="false"
        name="主页"
    >
      <template #label>
        <el-text style="margin-right: 6px">
          主页
        </el-text>
        <LcuProfile :size="20" :profile-id="summonerInfoStore().currentSummonerInfo?.profileIconId"/>
      </template>
      <PersonPage
          @jumpSummonerHomePage="handleJumpToOtherSummoner"
          :summonerInfo="summonerInfoStore().currentSummonerInfo"
          :summonerProfileInfo="summonerInfoStore().currentSummonerInfoProfile"
      ></PersonPage>
    </el-tab-pane>


    <el-tab-pane
        v-for="item in otherSummonerList"
        :closable="true"
        lazy
        :label="item.label"
        :key="item.value"
        :name="item.value"
    >
      <PersonPage
          @jumpSummonerHomePage="handleJumpToOtherSummoner"
          :summonerInfo="item.summonerInfo"
          :summonerProfileInfo="item.summonerProfileInfo"
      ></PersonPage>
    </el-tab-pane>
  </el-tabs>


</template>

<style scoped>

</style>